<template>
  <!-- 头部 -->
  <div>
    <div class="book_top ">
      <ul class="book_top_menu">
        <li>
      
        </li>
        <li>
          <router-link tag="span" to="/bookshelf" class="iconfont icon-B"></router-link>
          <router-link tag="span" to="/my" class="iconfont icon-B2"></router-link>
          <router-link tag="span" to="/search" class="iconfont icon-B1"></router-link>
        </li>
      </ul>
      <div style="text-align:center;">
        <ul class="book_top_Nav">
          <li class="book_top_Nav_up">推荐</li>
          <router-link to="/Vip" tag="li">VIP</router-link>
          <router-link tag="li" to="/new">更新</router-link>
          <router-link tag="li" to="/comment">书评</router-link>
          <router-link tag="li" to="/img">分类</router-link>


        </ul>
      </div>

    </div>
    <!-- 轮播图 -->
    <div class="bannerbox">
      <div class="swiper">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" @change="onChange">
          <router-link :to="'./BookContent?id=7'">
            <van-swipe-item>
              <img src="https://rs.sfacg.com/web/m/images/homePush/2022/10/b6b33cce-4205-4bff-8e6f-a0dcb547fdaf.png"
                alt="" style="width: 100%;display: block;height: 100%;">
            </van-swipe-item>
          </router-link>
          <router-link :to="'./BookContent?id=1'">
            <van-swipe-item><img
                src="https://rs.sfacg.com/web/m/images/homePush/2022/10/1c2a2a69-043e-4284-999b-5d403df8258f.png" alt=""
                style="width: 100%;display: block;height: 100%;">
            </van-swipe-item>
          </router-link>
          <router-link :to="'./BookContent?id=5'">
            <van-swipe-item>
              <img src="https://rs.sfacg.com/web/m/images/homePush/2022/10/99c081fa-b18c-4d48-874b-bbc236fdaad8.png"
                alt="" style="width: 100%;display: block;height: 100%;">
            </van-swipe-item>
          </router-link>
          <router-link :to="'./BookContent?id=10'">
            <van-swipe-item>
              <img src="https://rs.sfacg.com/web/m/images/homePush/2022/10/3819dc93-71d4-4175-a104-11ddd0934ac7.png"
                alt="" style="width: 100%;display: block;height: 100%;">
            </van-swipe-item>
          </router-link>
          <template #indicator>
            <div class="custom-indicator">
              <ul>
                <li :class="{ 'con': indexSwiper == 0 }"></li>
                <li :class="{ 'con': indexSwiper == 1 }"></li>
                <li :class="{ 'con': indexSwiper == 2 }"></li>
                <li :class="{ 'con': indexSwiper == 3 }"></li>
              </ul>
            </div>
          </template>
        </van-swipe>
      </div>

    </div>
    <div class="book_bk_qs1" style="margin-top:11.718px;overflow:hidden;">
      <div class="book_bk_qs1 book_Content_title" style="border-top-width:0px;margin:0 2.4%;">人气风向标(更新稳定有特点)</div>
      <ul class="recommended_list Linkfont" style="margin-top:11.718px;">
        <li v-for="(image, index) in newVip" :key="'ifo-' + index">
          <router-link :to="'./BookContent?id=' + image.id">
            <img :src="image.imc">
            <p>{{ image.name }}</p>
          </router-link>
        </li>

      </ul>
    </div>
    <div class="book_bk_qs1" style="margin-top:11.718px;overflow:hidden;">
      <div class="book_bk_qs1 book_Content_title" style="border-top-width:0px;margin:0 2.4%;">最新有意思的新书</div>
      <ul class="recommended_list Linkfont" style="margin-top:11.718px;">
        <li v-for="(image, index) in images1" :key="'in-fo-' + index" @click="toTask(image)">
          <img :src="image.imc">
          <p>{{ image.name }}</p>
        </li>


      </ul>
    </div>
    <div class="book_bk_qs1" style="margin-top:11.718px;overflow:hidden;">
      <div class="book_bk_qs1 book_Content_title" style="border-top-width:0px;margin:0 2.4%;">专题推荐</div>
      <ul class="fengtui_list Linkfont" style="margin-top:11.718px;">
        <li v-for="(image, index) in bookProject" :key="'info-' + index">
          <router-link :to="'./BookContent?id=' + image.id">
            <img :src="image.imc">
            <p>{{ image.name }}</p>
          </router-link>
        </li>

      </ul>
    </div>
  </div>
</template>


<script>
// import "../assets/font/iconfont";
// import Swiper from "swiper";
import { getJsonData } from '@/api/home';
export default {
  data() {
    return {
      indexSwiper: 0,
      bookProject: null,
      newVip: null,
      images1: null,
      bookId: null,



    };
  },
  created() {
     // 获取json数据
    getJsonData().then(data => {
      // console.log(data);
      // console.log(data.newvip[0].id);
      this.bookProject = data.bookProject
      this.newVip = data.newvip
      this.images1 = data.vip1
      // this.bookId=data.newvip.id
    });

  },
  methods: {
    // 轮播图
    onChange(index) {
      this.indexSwiper = index;
    },
    toTask(image) {
      //任务协同
      // 跳转页面
      console.log(image);
      // this.contentmouseleave(); //关闭下拉
      this.$router.push({
        path: `/BookContent?id=${image.id}`,

      }); //跳转页面
    }
  },
  beforeRouteLeave(to, from, next) {
    if (to.name === "BookContent") {
      this.$store.commit("newCachePath", to.path.split("/"));
      console.log(this.$store.state.cachePath);

    }
    next();
  },

}
</script>


<style lang="scss">
.fengtui_list {
  font-size: 0;
}

.fengtui_list li {
  display: inline-block;
  width: 30.1%;
  margin-left: 2.4%;
  text-align: center;
  vertical-align: top;
}

.fengtui_list li img {
  margin-bottom: 0.02rem;
  width: 100%;
}

body {
  background-color: #F3F3F3;
}

p {
  display: block;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
}

.Linkfont li {
  color: #666;
  text-decoration: none;
  font-size: 11.718px;
}

.recommended_list li {
  display: inline-block;
  width: 22%;
  margin-left: 2.4%;
  text-align: center;
  vertical-align: top;
}

.recommended_list li img {
  margin-bottom: 2.344px;
  width: 100%;
}

.recommended_list {
  font-size: 0;
}


.book_Content_title {
  text-align: left;
  color: #333;
  font-size: 14.062px;
  height: 35.154px;
  line-height: 35.154px;
}

.book_top {
  max-width: 750px;
  min-width: 375px;
  position: fixed;
  z-index: 90;
  width: 100%;
  top: 0;
  color: #666;
  border-top-width: 0px;
  background: #fff;
  margin: 0 auto;
}

.book_top_menu {
  margin: 5.859px 5.859px 0 5.859px;
  height: 24.608px;
  display: -webkit-box;

  li {
    display: -webkit-box;
    width: 50%;
    color: #f90;

    a {
      color: #f90;
    }

    &:last-child {
      -webkit-box-pack: end;
      -webkit-box-align: center;
    }

    span {
      font-size: 18.749px;
      padding: 0 10px;
    }
  }
}

.book_top_Nav {
  font-size: 16.405px;
  display: inline-block;

  li {
    display: inline-block;
    line-height: 46.872px;
    text-align: center;
    padding: 0 11.718px;
    border-bottom: 3px solid #fff;

    a {
      color: #666;
      display: block;
      width: 100%;
    }
  }
}

.book_top_Nav_up {
  border-bottom-color: #f90 !important;

  a {
    font-weight: bold;
    color: #f90 !important;
  }
}

.bannerbox {
  background-image: linear-gradient(#E9ECEC, #ffffff);
  height-min: 137px;

  .swiper {
    margin-top: 85px;
    background-color: aqua;

    overflow: hidden;

    .custom-indicator {
      width: 100%;
      position: absolute;
      left: 0px;
      bottom: 18px;
      text-align: center;

      ul {

        display: inline-block;
        margin: 0 auto;

        li {
          border-radius: 10px;
          display: inline-block;
          width: 7px;
          height: 7px;
          margin: 0px 5px;
          background-color: rgba(255, 255, 255, 0.6);

          &.con {
            background-color: #ff6600;
          }
        }
      }
    }
  }
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
</style>